﻿using System;
using System.Collections.Generic;
using System.Text;
using ElevatorLib;

namespace Examples
{
    class MinStopStrategy : BasicStrategy
    {
        public MinStopStrategy()
        {
            this.name = "MinStopStrategy";
            this.auther = "ability";
            this.description = "Mininum stopCount";
        }

        /// <summary>
        /// 派出最小停靠次数的电梯去接客
        /// </summary>
        /// <param name="floor"></param>
        /// <param name="isUp"></param>
        public override void DispatchStrategy(int floor, bool isUp)
        {
            Elevator minElevator = null;
            int minStop = Int32.MaxValue;
            foreach (Elevator elevator in Building.Elevators)
            {
                if (elevator.State == ElevatorState.FREE)
                {
                    minElevator = elevator;
                    break;
                }

                if (elevator.CurrentFloor == floor)
                {
                    continue;
                }

                if (elevator.StopCount <= minStop)
                {
                    minElevator = elevator;
                    minStop = elevator.StopCount;
                }
            }

            minElevator.RequestDispatch.Add(RequestConvert.FloorNoToValue(floor, isUp));

        }
    }
}
